package com.my.model;

import com.my.annotation.Remark;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Remark("统一的json返回格式")
public class Response<T> {

	@Remark("方法的实际返内容")
	private T data;
	@Remark("请求唯一标识")
	private String requestId;
	@Remark("请求是否成功")
	private boolean success;
	@Remark("异常信息")
	private String message;
	@Remark("请求执行状态,,0已发送,1执行中,2执行完毕")
	private Integer state;
	@Remark("版本号")
	private String version;
	@Remark("请求产生的异常,内部传输用,生成json的时候会忽略")
	private Throwable error;


	public static Response success(Object data) {
		Response resp = new Response();
		resp.setState(RequestState.FINISH.ordinal());
		resp.data = data;
		resp.success = true;
		return resp;
	}

	public static Response fail(String error) {
		Response resp = new Response();
		resp.setState(RequestState.FINISH.ordinal());
		resp.data = null;
		resp.success = false;
		resp.message = error;
		return resp;
	}

}
